<?php
/*
    Class: Todo_IndexController

    About: Author
    Jaybill McCarthy

    About: License
    <http://communit.as/docs/license>
*/
class Todo_IndexController extends Cts_Controller_Action_Admin {
    
    function indexAction(){		
		
		$request = new Cts_Request($this->getRequest());		
		$items_index_table = new TodoItemsIndex();
		
		// add something		
		//$items_table = new TodoItems();
		//$items_table->addForRole("member","admin","set house on fire",1,"blog");
		//$items_table->delete("id = 22");
		
		$users_table = new Users();
		
		$username = $this->_identity->username;
		
		$items = $items_index_table->fetchAll($items_index_table->select()
					->where("username = ?",$username)
					->where("completed = 0")
					);
		
		$tmp_items = array();
		if(count($items) > 0){
			foreach($items as $item){
				$item = $item->toArray();			
				$assigned_by_user = $users_table->fetchByUsername($item['assigned_by_username']);
				if(!is_null($assigned_by_user)){
					$item['assigned_by_user'] = $assigned_by_user->toArray();
				}
								
				$tmp_items[] = $item;		
			}
		}
		$this->view->items = $tmp_items;
				
    }

}